package com.yyw.foodie.service.transactiontest;

import com.yyw.foodie.pojo.StuEntity;
import com.yyw.foodie.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 易煜玮
 * @ClassName Service1.java
 * @Description 事务test
 * @createTime 2021年05月22日 15:41:00
 */
@Service
public class Service1 {

    @Autowired
    private StuService stuService;

    public void saveFather() {
        StuEntity stuEntity = new StuEntity("张三", 22);
        stuService.save(stuEntity);
    }

    @Transactional(propagation = Propagation.NESTED)
    public void saveChild() {
//        try {
            StuEntity stuEntity = new StuEntity("李四", 23);
            stuService.save(stuEntity);

            int i = 10 / 0;

            System.out.println("没有异常的话我就会被打印...");
//        } catch (Exception e) {
//            e.printStackTrace();
////            throw new RuntimeException();
//        }
    }
}
